#pragma once
#include "Engineobject.h"
#include "EngineDefine.h"
#include "Singleton.h"

namespace DreamEngine
{

class _EngineExport CDynLib : public CEngineObject
{
public:
	CDynLib(const CString& name);
	~CDynLib(void);
	
	const CString& GetName()const	{return m_name;}

	bool	Load();
	void	Free();
	void*	GetSymbol( const CString& strName ) const throw();

protected:

	CString			m_name;
	DynLibHandle	m_libHandle;
};

class _EngineExport CDynLibManager: public CEngineObject, public CSingleton<CDynLibManager>
{
public:

	CDynLibManager();
	~CDynLibManager();

	static CDynLibManager& Instance(void);
	static CDynLibManager* InstancePtr(void);

	CDynLib*	Load(const CString& libFile);
	bool		Free(const CString& libFile);
	CDynLib*	Get(const CString& libFile)const;
	void		FreeAll(void);

private:

	typedef std::vector<CDynLib*> DynLibLst;
	DynLibLst	m_dynlibs;
};

template<> CDynLibManager* CSingleton<CDynLibManager>::m_singleton = 0;

}


